﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;

namespace DAL
{
   public class OrderDetailsDAL
    {
        /// <summary>
        /// 订单详情
        /// </summary>
        //订单项添加
        public static int orderDetailsAdd(OrderDetails od,int id) {
        string sql = "insert into tb_OrderDetails(OrderID,FoodID,UserID,number) select @OrderID,FoodID,UserID,number from tb_Cart where UserID=" + id;
                SqlParameter[] para = {
                new SqlParameter("@OrderID",od.OrderID)
            };
                return SqlDBHelper.ExecuteNonQuery(sql, para);
        }
        //后台订单项查询
        public static DataTable orderDetailsCX(int id)
        {
            string sql = @"select od.OrderDetailsID,o.Ordertitle,f.FoodName,f.PicUrl,od.number,o.OrderName,f.FoodID,o.OrderID
                            from tb_OrderDetails od,tb_Order o,tb_Food f 
                            where od.OrderID=o.OrderID and od.FoodID=f.FoodID and o.OrderID=" + id;
            return SqlDBHelper.GetDataTable(sql);
        }
        //查询数据条数
        public static object dataNum()
        {
            string sql = "select count(*) from tb_OrderDetails";
            return SqlDBHelper.ExecuteScalar(sql);
        }
        //后台订单项详细
        public static DataTable orderDetailsXX(int id)
        {
            string sql = @"select od.OrderDetailsID,o.Ordertitle,f.FoodName,f.PicUrl,od.number,o.OrderName
                            from tb_OrderDetails od,tb_Order o,tb_Food f 
                            where od.OrderID=o.OrderID and od.FoodID=f.FoodID and od.OrderDetailsID="+id;
            return SqlDBHelper.GetDataTable(sql);
        }
        //前台订单项删除
        public static int orderDetailsDelete(int id)
        {
            string sql = "delete from tb_OrderDetails where OrderID =" + id;
            return SqlDBHelper.ExecuteNonQuery(sql);
        }
    }
}
